import { useRoute } from 'vue-router'
import { computed } from 'vue'

/**
 * 获取页面对应的状态
 * @param {Object} types - { add: '/page/path/add', edit, '/page/path/edit }
 */
export const usePageType = (types) => {
  return computed(() => {
    const { path } = useRoute()
    let pageType = ''

    Object.keys(types).forEach(key => {
      if (pageType) return
      if (path === types[key]) pageType = key
    })

    return pageType
  })
}
